package com.knife4jtest.controller;

import com.knife4jtest.entity.TUser;
import com.knife4jtest.service.TUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "用户管理")
@RestController
@RequestMapping("/TUser")
public class TUserController {

    @Autowired
    private TUserService userService;

    @ApiOperation(value = "新增用户", notes = "创建一个新的用户")
    @PostMapping
    public Boolean addTUser(@RequestBody TUser TUser) {
        Boolean result = userService.save(TUser);
        return result;
    }

    @ApiOperation(value = "删除用户", notes = "根据用户ID删除用户")
    @DeleteMapping("/{id}")
    public Boolean deleteTUser(
            @ApiParam(value = "用户ID", required = true, example = "1")
            @PathVariable Integer id) {
        return userService.removeById(id);
    }

    @ApiOperation(value = "更新用户", notes = "根据用户ID更新用户信息")
    @PutMapping
    public Boolean updateTUser(@RequestBody TUser TUser) {
        return userService.updateById(TUser);
    }

    @ApiOperation(value = "获取所有用户列表", notes = "获取系统中所有用户的列表")
    @GetMapping
    public List<TUser> geTUsers() {
        return userService.list();
    }

    @ApiOperation(value = "根据ID查询用户", notes = "根据用户ID获取用户详细信息")
    @GetMapping("/{id}")
    public TUser geTUser(
            @ApiParam(value = "用户ID", required = true, example = "1")
            @PathVariable Integer id) {
        return  userService.getById(id);
    }
}